package dev.devlok.springcloudstreamzeromqbindersample;

import org.zeromq.SocketType;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

public class ZeroMqConsumer {
    public static void main(String [] args)
    {
        ZContext zContext = new ZContext();
        ZMQ.Socket socket = zContext.createSocket(SocketType.SUB);
        socket.connect("tcp://localhost:6002");
        socket.subscribe("output".getBytes(ZMQ.CHARSET));



        for(int i = 0;i< 100; i++) {
            String topic = socket.recvStr();
            String data = socket.recvStr();

            System.out.println(topic);
            System.out.println(data);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        socket.disconnect("tcp://localhost:6002");
        zContext.destroy();

    }
}
